package com.boarsoft.message.broker;

import java.util.List;
import java.util.Map;

import com.boarsoft.message.bean.MessageEntity;
import com.boarsoft.message.bean.MessageQueryParam;
import com.boarsoft.message.bean.TargetMQ;
import com.boarsoft.message.bean.TargetQueueInfo;

/**
 * 消息broker管控接口，供message-web调用: <br>
 * 1、队列初始化，实现队列的动态添加、删除和查询<br>
 * 2、队列监控，向message-web返回队列监控信息<br>
 * 
 * @author Mac_J
 *
 */
public interface MessageBroker {

	/**
	 * 
	 * 
	 * @param key
	 *            key of TargetMQ
	 * @param xml
	 *            XML file content of TargetMQ
	 * @return
	 */
	Object addTargetQueue(String key, String xml);

	/**
	 * 
	 * @param key
	 *            key of TargetMQ
	 * @return Map<String, ReplyInfo<Object>> key = addr
	 */
	Object activeTargetQueue(String key);

	/**
	 * 
	 * @param key
	 *            key of TargetMQ
	 * @return
	 */
	Object deactiveTargetQueue(String key);
	
	/**
	 * 
	 * @param key
	 *            key of TargetMQ
	 * @return Map<String, ReplyInfo<Object>> key = addr
	 */
	Object activeRecipientQueue(String key);

	/**
	 * 
	 * @param key
	 *            key of TargetMQ
	 * @return
	 */
	Object deactiveRecipientQueue(String key);

	/**
	 * 移除某个队列，并清空队列中的消息
	 * 
	 * @param key
	 * @param force
	 *            是否丢弃队列中的消息。
	 * @return
	 */
	Object removeTargetQueue(String key, boolean force);

	Object updateTargetQueue(String code, String xml);

	Object updateRecipientQueue(String code, String xml) throws Throwable;

	Object addRecipientQueue(String key, String xml) throws Throwable;

	Object removeRecipientQueue(String key, boolean force);

	Object addTargetQueue(String key, TargetMQ tq);

	Object statTargetQueue();

	/**
	 * 
	 * @param target
	 * @return
	 */
	Object statTargetQueue(String target);

	/**
	 * 广播调用时返回 Map<String, Map<String, RecipientQueueInfo>><br>
	 * 形如：{ addr: { recipientQueueName: recipientQueueInfo } }<br>
	 * 非广播调用时返回 Map<String, RecipientQueueInfo>
	 * 
	 * @return
	 */
	Object statRecipientQueue();

	Object statRecipientQueue(String target);

	/**
	 * 
	 * @return
	 */
	Map<String, TargetQueueInfo> getTargetQueue();

	/**
	 * 
	 * @param target
	 * @param mqp
	 * @return
	 */
	List<MessageEntity> query(String target, MessageQueryParam mqp);

	/**
	 * 
	 * @param target
	 * @param mqp
	 * @return
	 */
	Object count(String target, MessageQueryParam mqp);
}